<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"  import="com.youle.model.Item, java.util.List"%>
<%
	List<Item> packetItems = (List<Item>) request.getAttribute("packetItems");
	if (packetItems != null) {
		System.out.println("当前容器道具数 ： " + packetItems.size());
	}
	//System.out.println("whereami == " + session.getAttribute("whereami"));
	Integer mapid = (Integer) request.getAttribute("mapid");
	System.out.println("mapid ： " + mapid);
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>打开背包</title>
<style type="text/css">
body {
	font-size:12px;
}
#wrap {
	width:90%;
	margin:auto;
}
#itemtitle {
	padding:3px 5px;
	background-color:#72b653;
	font-size:16px;
	font-weight:bold;
	color:#fff;
	letter-spacing:5px; 
	text-align:center;
}
#itemlist {
	padding:5px;
	text-align:center;
}
#itemlist input {
	vertical-align:middle;
}
</style>
<script type="text/javascript" src="js/jquery-1.7.2.js"></script>
<script>
function useitem(userid, itemid) {
	$.post("useitem.action", {
		userid: userid,
		itemid: itemid
    },
    function(json) {
        var messages = json.message;
        if ("notHome" == messages) {
            alert("请在家中使用这件道具！");
        } else if ("usernull" == messages) {
            alert("用户非法！");
        } else {
            $('#' + messages + '_item').remove();
            window.parent.opener.location.href = window.parent.opener.location.href;
        }
    });
	
}
function delitem(itemid) {
	$.post("delitem.action", {
		itemid: itemid
    },
    function(json) {
        var messages = json.message;
        if ("delitemok" == messages) {
            alert("删除成功。");
            $('#' + messages + '_item').remove();
            location.href = location.href;
        } else if ("usernull" == messages) {
            alert("用户非法。");
        } else {
        	alert("删除失败。");
            $('#' + messages + '_item').remove();
        }
    });
}

function dropitem(mapid, itemid) {
	$.post("dropitem.action", {
		mapid: mapid,
		itemid: itemid
    },
    function(json) {
        var messages = json.message;
        if ("dropitemok" == messages) {
            alert("扔掉道具成功。");
            $('#' + messages + '_item').remove();
            location.href = location.href;
            window.parent.opener.location.href = window.parent.opener.location.href;
        } else if ("usernull" == messages) {
            alert("用户非法。");
        } else {
        	alert("扔掉道具失败。");
        }
    });
}
</script>
</head>
<body>
	<div id="wrap">
		<div id="itemtitle">
			我的物品<label>（<%=packetItems.size() %>/30）</label>
		</div>
		<div id="itemlist">
			<%
			if (packetItems != null) {
				for (Item item : packetItems) {
			%>	
				<div id="<%=item.getId() %>_item">
					<input id="<%=item.getId() %>" type="checkbox" value="<%=item.getId() %>"/>
					<label for="<%=item.getId() %>"><%=item.getName() %></label>
					<a href="javascript:useitem(<%=request.getAttribute("userid") %>, <%=item.getId() %>);">使用</a>
					<a href="javascript:dropitem(<%=mapid %>, <%=item.getId() %>);">扔掉</a>
					<a href="javascript:delitem(<%=item.getId() %>);">删除</a>
				</div>
			<%
				}
			}
			%>
		</div>
	</div>
</body>
</html>